-- {...}
print("{...}: ")
function add (...)
	local sum = 0
	for _, v in ipairs({...}) do 	-- error may happen if {...} contain nil
		sum = sum + v
	end
	return sum
end

print(add(3, 4, 5, 7, 8, 9))

-- table.pack(...)
print("table.pack(...): ")
function nonils (...)
	local arg = table.pack(...) 	-- simaliar to {...} execept the extra field n (the number of elements)
	for i = 1, arg.n do  					-- arg.n is the number of elements
		if arg[i] == nil then
			return false
		end
	end
	return true
end

print(nonils())
print(nonils(2, 35, nil))

-- select(selector, ...)
-- if selector is number, it means return the args after the nth arg
-- if selector is "#", it means return the number of args
print("select(selector, ...): ")
print(select(1, "a", "b", "c")) 	-- a b c
print(select(2, "a", "b", "c")) 	-- b c
print(select(3, "a", "b", "c")) 	-- c
print(select("#", "a", "b", "c"))	-- 3

function newadd(...)
	local sum = 0
	for i = 1, select("#", ...) do
		sum = sum + select(i, ...) 	-- auto truncate the return value
	end
	return sum
end

print("sum: " .. newadd(1, 2, 3, 4, 5))
